<template>
  <div class="imagePage">
    <van-nav-bar
      title="客户推广"
      left-text=""
      left-arrow
      @click-left="onClickLeft"
      :fixed="true"
      :placeholder="true"
    />
    <!-- 推荐好友 -->
    <div class="recommend">
      <!-- <div class="sjrz" style=";text-align: center;">
				团洗商户推广
			</div> -->
      <div class="content">
        <!-- <img class="codeTwo" :src="promotion_code" /> -->
        <van-image width="10rem" height="10rem" fit="contain" :src="promotion_code" />
        <div class="title">
          <div class="getCode">专属邀请码</div>
          <div class="dash">
            {{ promotion_url }}
            <div class="btn" id="btn" :data-clipboard-text="promotion_url"  @click="copyText()">复制</div>
					</div>
          <BorderDashed />
          <div class="">扫码邀请>推广有礼>权益享受</div>
          <div class="longPush">长按图片保存到相册</div>
        </div>
      </div>
      <div class="title2">
        <img :src="shareImg" />
      </div>
      <van-button
        round
        block
        native-type="submit"
        color="linear-gradient(90deg, #218CC9 0%, #2CB9A4 105%)"
        @click="sharePoster"
      >
        分享海报
      </van-button>
    </div>
  </div>
</template>

<script setup>
import { getPromotionCode } from "@/services";
import BorderDashed from "@/components/border-dashed/border-dashed.vue";
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { showToast } from "vant";
import Clipboard from "clipboard";

const router = useRouter();
import { getAssetURL } from "@/utils/load_assets.js";
const promotion_code = ref("");
const promotion_url = ref("");
const shareImg = getAssetURL("common/codeShare.png");
const poster = ref("");
onMounted(() => {
  getPageData();
});
const getPageData = async () => {
  let res = await getPromotionCode();
  promotion_code.value = res.data.promotion_code;
  promotion_url.value = res.data.promotion_url;
  poster.value = res.data.promotion_share;
  console.log(res, 11);
};
const sharePoster = () => {
  router.push({
    path: "/sharePoster",
    query: {
      poster: poster.value,
    },
  });
};
// const startDateStr = computed(() => formatMonthDay(startDate.value))
// 返回按钮
const onClickLeft = () => {
  router.back();
};
// 复制
const copyText = () => {
  var clipBoard = new Clipboard("#btn");
  clipBoard.on("success", () => {
    clipBoard.destroy();
    clipBoard = new Clipboard("#btn");
    showToast("复制成功");
  });
  clipBoard.on("error", () => {
    showToast("复制失败，请手动复制");
  });
};
</script>

<style lang="less">
.sjrz {
  text-align: center;
  box-shadow: 0px 0px 5px rgba(151, 151, 151, 0.1);
  box-sizing: border-box;
  border-radius: 5px;
  width: 100%;
  padding: 10px;
  background: #fff;
}

.title2 {
  margin-top: 10px;
  width: 100%;
  margin-left: -20px;
  margin-right: -20px;

  img {
    width: 100%;
  }
}

.imagePage {
  padding: 20px;

  .recommend {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    // padding: 0px 20px 20px 20px;

    .content {
      box-shadow: 0px 0px 5px rgba(151, 151, 151, 0.1);
      box-sizing: border-box;
      border-radius: 5px;
      background: #fff;
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 20px;
      margin-top: 20px;

      .longPush {
        color: #2cb9a4;
      }

      // image {
      // 	width: 100%;
      // 	margin: 20px 0;
      // }
    }

    .title {
      width: 100%;
      text-align: center;
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .getCode {
      margin: 10px;
    }

    .dash {
      font-size: 14px;
      width: 95%;
      padding: 11px 0 0 0;
      border-top: 1px dashed #979797;
    }

    .codeTwo {
      width: 169px;
      height: 170px;
    }

    .btn {
      color: #409eff;
      font-size: 14px;
      margin-left: 10px;
      display: inline-block;
    }

    .invitation {
      background: #1fc064;
      color: #fff;
      bottom: 200px;
      left: 50%;
      transform: translateX(-50%);
    }

    .generate {
      background: #dcdcdc;
      color: #7f8084;
      bottom: 70px;
      left: 50%;
      transform: translateX(-50%);
    }
  }

  .PKWin,
  .PKNegative {
    image {
      width: 100%;
      height: 100%;
    }

    .btn {
      width: 80%;
      height: 96px;
      line-height: 96px;
      text-align: center;
      border-radius: 96px;
      font-size: 28px;
      font-weight: 500;
      position: fixed;
      background: #000;
      color: #fff;
      bottom: 240px;
      left: 50%;
      transform: translateX(-50%);
    }
  }
}
</style>
